package com.jwthhealth_pub.old.physicalfitness.view;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.old.physicalfitness.view.adapter.phesicalFitnessAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 体适能调查问卷
 * Created by Administrator on 2016/12/20.
 */
public class PhysicalFitnessActivity extends Activity {
    @BindView(R.id.rv_physicalfitness)
    RecyclerView rvPhysicalfitness;
    @BindView(R.id.progressbar)
    ProgressBar progressbar;
    @BindView(R.id.sign_topbar)
    TitleLayout signTopbar;
    private phesicalFitnessAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_physicalfitness);
        ButterKnife.bind(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        initClick();
        initRecycleView();
    }

    private void initRecycleView() {
        rvPhysicalfitness.setLayoutManager(new LinearLayoutManager(this));
        adapter = new phesicalFitnessAdapter(this);
        rvPhysicalfitness.setAdapter(adapter);
    }

    private void initClick() {
        signTopbar.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }

    public void progressbar() {
        progressbar.setVisibility(View.VISIBLE);
    }

    public void progressBar(int isVisibility) {
        if (isVisibility == View.GONE) {
            progressbar.setVisibility(View.GONE);
        } else if (isVisibility == View.VISIBLE) {
            progressbar.setVisibility(View.VISIBLE);
        }
    }

//    @OnClick(R.id.btn_save)
//    public void onViewClicked() {
//        if (adapter == null) return;
//        List<Integer> answers = adapter.getAnswers();
//        for (int i = 0; i < 7; i++) {
//            if (answers.get(i) == -1) {
//                Toast.makeText(this, getResources().getString(R.string.physicalfiness_alert), Toast.LENGTH_SHORT).show();
//                return;
//            }
//        }
//        // TODO: 2016/12/20 提交操作 跳转到下一个界面
//        String answer = "";
//        for (int i = 0; i < 7; i++) {
//            answer = answer + answers.get(i) + ",";
//        }
//        answer = answer.substring(0, answer.length() - 1);
//
//        LoginModel.DataBean userinfoModel = UserInfoDao.getInstance().queryUserinfoModel();
//        Call<PhysicalAnswerModel> constitutionCompleteModelCall;
//        if (userinfoModel != null) {
//            constitutionCompleteModelCall = ApiHelper.physicalCommit(userinfoModel.getId(), answer, userinfoModel.getAndroidtoken());
//        } else {
//            constitutionCompleteModelCall = ApiHelper.physicalCommit(null, answer, null);
//        }
//
//        constitutionCompleteModelCall.enqueue(new Callback<PhysicalAnswerModel>() {
//            @Override
//            public void onResponse(Call<PhysicalAnswerModel> call, Response<PhysicalAnswerModel> response) {
//                final PhysicalAnswerModel physicalAnswerModel = response.body();
//                if (physicalAnswerModel.getCode().equals("0")) {
//                    Intent intent = new Intent(PhysicalFitnessActivity.this, PhysicalFitnessAnswerActivity.class);
//                    if (physicalAnswerModel.getData().getResult().equals(adapter.PHYSICALFINESSANSWER_NO)) {
//                        intent.putExtra(Constant.PHYSICAL_ANSERT, false);
//                    } else {
//                        intent.putExtra(Constant.PHYSICAL_ANSERT, true);
//                    }
//                    startActivity(intent);
//                    finish();
//                } else {
//                    runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            Toast.makeText(PhysicalFitnessActivity.this, physicalAnswerModel.getMsg(), Toast.LENGTH_SHORT).show();
//                            progressBar(View.GONE);
//                        }
//                    });
//                }
//            }
//
//            @Override
//            public void onFailure(Call<PhysicalAnswerModel> call, Throwable t) {
//
//            }
//        });
//        progressbar();
//    }
}
